package com.spark.modules.generation.entity.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 实体类字段参数
 *
 * @author LYCHEE
 * @date 2025/2/17 13:05
 */
@Data
@NoArgsConstructor
public class GeneratorFieldsProperties implements Serializable {
    public GeneratorFieldsProperties(String fieldName, String fieldType, String fieldAnnotation, String fieldRemark, boolean openQuery, String queryType){
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.fieldRemark = fieldRemark;
        this.fieldAnnotation = fieldAnnotation;
        this.openQuery = openQuery;
        this.queryType = queryType;
    }

    public GeneratorFieldsProperties(String fieldName, String fieldType, String fieldAnnotation, String fieldRemark, boolean openQuery, String queryType, Validation validation){
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.fieldRemark = fieldRemark;
        this.fieldAnnotation = fieldAnnotation;
        this.openQuery = openQuery;
        this.queryType = queryType;
        this.validation = validation;
    }

    public GeneratorFieldsProperties(String fieldName, String fieldType, String fieldAnnotation, String fieldRemark, boolean openQuery, String queryType, Validation validation, Dict dict){
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.fieldRemark = fieldRemark;
        this.fieldAnnotation = fieldAnnotation;
        this.openQuery = openQuery;
        this.queryType = queryType;
        this.validation = validation;
        this.dict = dict;
    }

    public GeneratorFieldsProperties(String fieldName, String fieldType, String fieldAnnotation, String fieldRemark, boolean openQuery, String queryType, Dict dict){
        this.fieldName = fieldName;
        this.fieldType = fieldType;
        this.fieldRemark = fieldRemark;
        this.fieldAnnotation = fieldAnnotation;
        this.openQuery = openQuery;
        this.queryType = queryType;
        this.dict = dict;
    }

    /**
     * 字段属性名称
     */
    private String fieldName;

    /**
     * 字段类型
     */
    private String fieldType;

    /**
     * 字段注释
     */
    private String fieldAnnotation;

    /**
     * 字段备注
     */
    private String fieldRemark;

    /**
     * 是否开启查询
     */
    private boolean openQuery = false;

    /**
     * 查询类型
     */
    private String queryType = "EQ";

    /**
     * 数据校验信息
     */
    private Validation validation;

    /**
     * 字典
     */
    private Dict dict;

    /**
     * 数据校验信息
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Validation{

        public Validation(boolean canNotNull, boolean openPattern){
            this.canNotNull = canNotNull;
            this.openPattern = openPattern;
        }

        public Validation(boolean canNotNull, boolean openPattern, int patternType, String regexp, String regexpMsg){
            this.canNotNull = canNotNull;
            this.openPattern = openPattern;
            this.patternType = patternType;
            this.regexp = regexp;
            this.regexpMsg = regexpMsg;
        }

        /**
         * 检验字段最小值
         */
        private int validationMin = 0;

        /**
         * 检验字段最大值
         */
        private int validationMax = 0;

        /**
         * 是否不能为空
         */
        private boolean canNotNull = false;

        /**
         * 是否开启正则校验
         */
        private boolean openPattern = false;

        /**
         * 正则检验规则0内置规则，1自定义正则规则
         */
        private int patternType = 0;

        /**
         * 校验规则
         */
        private String regexp;

        /**
         * 检验规则提示
         */
        private String regexpMsg;
    }

    /**
     * 字典参数
     */
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public static class Dict{

        public Dict(String dictCode){
            this.openDict = true;
            this.dictCode = dictCode;
        }

        public Dict(String dictTable, String dictCode, String dictText){
            this.openDict = true;
            this.dictType = 1;
            this.dictCode = dictCode;
            this.dictText = dictText;
            this.dictTable = dictTable;
        }

        /**
         * 是否字典
         */
        private boolean openDict = false;

        /**
         * 字典类型
         *  : 0数据字典 1表字典
         */
        private int dictType = 0;

        /**
         * 字典编码
         */
        private String dictCode;

        /**
         * 字典文本
         */
        private String dictText;

        /**
         * 字典表
         */
        private String dictTable;
    }
}
